#include <iostream>
#include <algorithm>

using namespace std;

#define lowbit(x) (x & -x)

void add(int *c, int i, int x, int n) {
    while (i <= n) {
        c[i] += x;
        i += lowbit(i);
    }
}

int query(int *c, int i) {
    int sum = 0;
    while (i) {
        sum += c[i];
        i -= lowbit(i);
    }
    return sum;
}

int bs(int *c, int n, int x) {
    int l = 1, r = n, mid;
    while (l < r) {
        mid = (l + r) >> 1;
        if (query(c, mid) < x) l = mid + 1;
        else r = mid;
    }
    return l;
}

int main() {
    int n, *cnt, *val, *c, *ans;
    cin >> n;
    cnt = new int[n + 5];
    val = new int[n + 5];
    c = new int[n + 5];
    ans = new int[n + 5];

    for (int i = 1; i <= n; ++i) {
        cin >> cnt[i] >> val[i];
        add(c, i, 1, n);
    }

    for (int i = n; i >= 1; --i) {
        int ind = bs(c, n, cnt[i] + 1);
        add(c, ind, -1, n);
        ans[ind] = val[i];
    }

    for (int i = 1; i <= n; ++i) {
        i == 1 || cout << " ";
        cout << ans[i];
    }
    cout << endl;

    delete [] cnt, val, c, ans;

    return 0;
}